package com.tan.androidtest.util;

import android.app.Activity;
import android.app.Dialog;
import android.view.LayoutInflater;
import android.view.View;

import com.tan.androidtest.R;

/**
 * Dialog工具类
 */

public class DialogUtil {

    private static Dialog loadingDialog;

    public static void showLoadingDialog(Activity activity) {
        if (activity == null || activity.isFinishing()) {
            return;
        }
        if (loadingDialog != null) {
            loadingDialog.cancel();
        }

        loadingDialog = new Dialog(activity, R.style.DialogStyle);
        View view = LayoutInflater.from(activity).inflate(R.layout.loading_dialog_layout, null);
        loadingDialog.setContentView(view);
        loadingDialog.setCanceledOnTouchOutside(false);
        loadingDialog.show();
    }

    public static void dismissLoadingDialog(Activity activity) {
        if (activity == null || activity.isFinishing()) {
            return;
        }
        if (loadingDialog != null && loadingDialog.isShowing()) {
            loadingDialog.dismiss();
        }
    }

}
